package protocol.JT905_2014;

import java.util.HashMap;

public class Handle905_2014JT84 implements IHandle905_2014JT {
    @Override
    public String handle(JT_905_2014Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle8400(cmd);
            case 0x01:
                return handle8401(cmd);
            default:
                return "905:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle8401(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:设置电话本");
        builder.append("\r\n");

        int size = cmd.readInt(1);

        builder.append("联系人总数:"+size);
        builder.append("\r\n");
        for (int i= 0;i < size;i++){

            HashMap<Integer,String> list = new HashMap<>();
            list.put(1,"呼入");
            list.put(2,"呼出");
            list.put(3,"呼入/呼出");
            builder.append("标志:"+list.getOrDefault(cmd.readInt(1),"未定义"));
            builder.append("\r\n");

            builder.append("电话号码:"+cmd.readString(-1));
            builder.append("\r\n");

            builder.append("联系人:"+cmd.readString(-1));
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle8400(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("平台->终端:电话回拨");
        builder.append("\r\n");

        builder.append("通话类型:"+((cmd.readInt(1) == 1)?"监听电话":"普通通话"));
        builder.append("\r\n");
        builder.append("电话号码:"+cmd.readString(-1));
        builder.append("\r\n");

        return builder.toString();
    }
}
